package com.base.commonlib.http;

import com.base.commonlib.base.BaseApp;
import com.base.commonlib.sp.SpUtil;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;

/**
 * Date：2019/3/25 下午2:12
 * Creator：arvin
 * Des：
 */

class OkHttpInitial {




    private static final long READTIMEOUT = 20000l;
    private static final long WRITETIMEOUT = 20000l;
    private static final long CONNECTTIMEOUT = 20000l;
    private static final TimeUnit UNIT = TimeUnit.MILLISECONDS;

    private static class HolderClass {
        private final static OkHttpClient sInstance = get();
    }


    private static OkHttpClient get() {
        //开启Log
        HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
        logInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);

        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.readTimeout(READTIMEOUT, UNIT);
        builder.writeTimeout(WRITETIMEOUT, UNIT);
        builder.connectTimeout(CONNECTTIMEOUT, UNIT);
        builder.retryOnConnectionFailure(false);

        builder.addInterceptor(logInterceptor);

        NetWorkInitial.addCustom(builder);
        NetWorkInitial.setCertificates(builder);

        return builder.build();
    }

    static OkHttpClient getInstance() {
        return OkHttpInitial.HolderClass.sInstance;
    }








}
